const app = getApp();
const uuidUtil = require('../../utils/uuid.js');
const util = require('../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    personInfo:{},
    dateValue1: '',
    dateValuee1: '',
    max: 250,
    statusArr:['上班','休假'],
    statusArrCode:['1','2'],
    index:null,
    pcikername1:null,
  },
  pickerchange:function(e){
    var that = this;
    let personinfo = that.data.personInfo;
    personinfo.adc251 = that.data.statusArrCode[e.detail.value];
    that.setData({
      pcikername1:'0',
      index:e.detail.value,
      personInfo:personinfo
    });
  },
  datePickerBindchange1:function(e){
    var that = this;
    var personinfo = that.data.personInfo;
    personinfo.adc252 = e.detail.value;
    that.setData({
        dateValue1:e.detail.value,
        personInfo : personinfo
    })
  },
  datePickerBindchangee1:function(e){
    var that = this;
    var personinfo = that.data.personInfo;
    personinfo.adc253 = e.detail.value;
    that.setData({
        dateValuee1:e.detail.value,
        personInfo : personinfo
    })
  },
  getAdc251:function(e){
    var that = this;
    let _dateValuee1 = '';
    var personinfo = that.data.personInfo;
    personinfo.adc251Name = e.detail.name;
    personinfo.adc251 = e.detail.id;
    if(personinfo.adc251=='1'){//上班
        _dateValuee1 = that.data.dateValuee1;
    }else{//休息
        personinfo.adc253 = '';
        personinfo.adc254 = '';
    }
    that.setData({
      personInfo : personinfo,
      dateValuee1 : _dateValuee1
    })
  },
  
  toSubmitPerson:function(){
    var that = this;
    var formdata = that.data.personInfo;
    if(formdata.adc251 == null||formdata.adc251==''){
        wx.showToast({
            title: '请选择工作状态!',
            icon: 'none',
            duration: 2000
        });
        return;
    }else{
        if(formdata.adc251=='1'){//上班
            if(formdata.adc253 == null||formdata.adc253==''){
                wx.showToast({
                    title: '请选择时间!',
                    icon: 'none',
                    duration: 2000
                });
                return;
            }
            if(formdata.adc254 == null||formdata.adc254==''){
                wx.showToast({
                    title: '请填写工作内容!',
                    icon: 'none',
                    duration: 2000
                });
                return;
            }
        }
    }
    if(formdata.adc252 == null||formdata.adc252==''){
        wx.showToast({
            title: '请选择日期!',
            icon: 'none',
            duration: 2000
        });
        return;
    }
    let planlistitem = {
        'id':uuidUtil.uuid(),
        'adc251':formdata.adc251,
        'adc252':formdata.adc252,
        'adc253':formdata.adc253,
        'adc254':formdata.adc254,
        'week':util.getWeekByDate(formdata.adc252)
    }
    wx.showModal({
        title: '提示',
        content: '是否确认保存？',
        success (resp) {
            if(resp.confirm){
                app.globalPlanList.push(planlistitem);
                if(formdata.adc251 == '1'){//工作
                    app.globalWorkDate.onwork.push(formdata.adc252)
                }else if(formdata.adc251 == '2'){//休息
                    app.globalWorkDate.onrest.push(formdata.adc252)
                }
                wx.navigateBack({
                    delta: 1
                })
            }
        }
    })
    
  },
  formTextareatChange(e) {
   const {field} = e.currentTarget.dataset;
   var value = e.detail.value;
   var len = parseInt(value.length);
   if (len > this.data.max) return;
   this.setData({
     currentWordNumber: len, //当前字数 
     [`personInfo.${field}`]: e.detail.value
   });
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    var that = this;
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    var that = this;
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})